package com.zxbit.uangstore.view;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.zxbit.uangstore.R;
import com.zxbit.uangstore.business.DialogManager;

public class GrantPermissionDialog {
    private AlertDialog dialog;
    private GrantPermissionDialogCallBack callBack;

    public GrantPermissionDialog(Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = View.inflate(context, R.layout.dialog_grant_permission_layout, null);
        TextView tv_title = view.findViewById(R.id.tv_tile);
        TextView tv_content = view.findViewById(R.id.tv_content);
        Button confirm = view.findViewById(R.id.confirm_button);
        final Button cancel = view.findViewById(R.id.cancel_button);
        tv_title.setText(context.getResources().getString(R.string.privacy_agreement_title));
        tv_content.setText(context.getResources().getString(R.string.privacy_agreement_content));
        builder.setView(view);
        builder.setCancelable(false);
        dialog = builder.create();

        Window window = dialog.getWindow();
        window.setGravity(Gravity.CENTER);
        window.getDecorView().setPadding(28, 28, 28, 28);
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏
        // 不允许取消
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null)
                    callBack.onConfirm();
            }
        });


        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null)
                    callBack.onCancel();
                hide();
            }

        });

    }

    public void show() {
        DialogManager.getManager().showDialogStack(dialog);
    }

    public void hide() {
        DialogManager.getManager().dismissDialog(dialog);
    }

    public void setOnClickListener(GrantPermissionDialogCallBack callBack) {
        this.callBack = callBack;
    }

    public interface GrantPermissionDialogCallBack {
        void onConfirm();

        void onCancel();
    }


}
